package com.lapelittle.order.mapper;

import com.lapelittle.order.entity.SaleOrder;
import com.lapelittle.order.mapper.provider.SaleOrderProvider;
import com.lapelittle.order.query.SaleOrderQuery;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SaleOrderMapper {
    
    @Insert("INSERT INTO sale_order(" +
            "id,shop_name, order_no, receiver_address, receiver_name, receiver_phone, " +
            "express_company, express_no, template_name, order_time, pay_time, " +
            "delivery_time, product_name, product_props, merchant_code, quantity, " +
            "pay_amount, import_time, update_time) " +
            "VALUES(" +
            "#{id},#{shopName}, #{orderNo}, #{receiverAddress}, #{receiverName}, #{receiverPhone}, " +
            "#{expressCompany}, #{expressNo}, #{templateName}, #{orderTime}, #{payTime}, " +
            "#{deliveryTime}, #{productName}, #{productProps}, #{merchantCode}, #{quantity}, " +
            "#{payAmount}, NOW(), NOW())")
    int insert(SaleOrder order);
    
    @Select("SELECT * FROM sale_order WHERE order_no = #{orderNo}")
    SaleOrder findByOrderNo(String orderNo);
    
    @Update("UPDATE sale_order SET " +
            "id = #{id},shop_name = #{shopName}, receiver_address = #{receiverAddress}, " +
            "receiver_name = #{receiverName}, receiver_phone = #{receiverPhone}, " +
            "express_company = #{expressCompany}, express_no = #{expressNo}, " +
            "template_name = #{templateName}, order_time = #{orderTime}, " +
            "pay_time = #{payTime}, delivery_time = #{deliveryTime}, " +
            "product_name = #{productName}, product_props = #{productProps}, " +
            "merchant_code = #{merchantCode}, quantity = #{quantity}, " +
            "pay_amount = #{payAmount}, update_time = NOW() " +
            "WHERE order_no = #{orderNo}")
    int update(SaleOrder order);
    
    @SelectProvider(type = SaleOrderProvider.class, method = "queryList")
    List<SaleOrder> queryList(SaleOrderQuery query);
    
    @SelectProvider(type = SaleOrderProvider.class, method = "queryCount")
    Long queryCount(SaleOrderQuery query);
} 